﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace IceZero.Business.Models
{
    /// <summary>
    /// 错误码
    /// </summary>
    public static class ExceptionCode
    {
        /// <summary>
        /// 错误消息字典
        /// </summary>
        
        private static readonly Dictionary<string, string> _msgDict;
        /// <summary>
        /// 简体中文
        /// </summary>
        public static readonly string langCN = "_cn";
        /// <summary>
        /// 英文
        /// </summary>
        public static readonly string langEN = "_en";
        /// <summary>
        /// 日语
        /// </summary>
        public static readonly string langJP = "_jp";
        /// <summary>
        /// 繁体中文
        /// </summary>
        public static readonly string langCNTW = "_cn-tw";

        static ExceptionCode()
        {
            _msgDict = new Dictionary<string, string>();
            InitMsgDict();
        }

        /// <summary>
        /// 通过code获取对应消息，没有匹配的返回null
        /// </summary>
        /// <param name="code"></param>
        /// <param name="lang"></param>
        /// <returns></returns>
        public static string GetMsg(string code, string lang = "_cn")
        {
            code += lang;
            if (!_msgDict.ContainsKey(code))
            {
                return null;
            }
            return _msgDict[code];
        }

        /// <summary>
        /// 通用错误码
        /// </summary>
        public static string CError = "CD001";

        /// <summary>
        /// 通用正确码
        /// </summary>
        public static string COK = "CD002";

        /// <summary>
        /// 已达到最大值
        /// </summary>
        public static string CMax = "CD003";

        /// <summary>
        /// 参数错误码
        /// </summary>
        public static string CArgError = "CD004";

        /// <summary>
        /// 已达到最小值
        /// </summary>
        public static string CMin = "CD005";

        /// <summary>
        /// 初始化信息字典
        /// </summary>
        private static void InitMsgDict()
        {
            _msgDict.Add(CError + langCN, "错误");
            _msgDict.Add(CError + langEN, "Error");
            _msgDict.Add(CError + langJP, "エラー");
            _msgDict.Add(CError + langCNTW, "錯誤");

            _msgDict.Add(COK + langCN, "正确");
            _msgDict.Add(COK + langEN, "Right");
            _msgDict.Add(COK + langJP, "正しいです");
            _msgDict.Add(COK + langCNTW, "正確");

            _msgDict.Add(CMax + langCN, "已达到最大值");

            _msgDict.Add(CMin + langCN, "已达到最小值");

            _msgDict.Add(CArgError + langCN, "参数 {0} 的值无效");
        }
    }
}
